<!-- 物流信息 -->
<template>
  <div class="table">
    <!-- 列表 -->
    <SearchTable v-model:formStatus="formStatus" @handleViewEdit="handleViewEdit" ref="searchTableRef" />
    <!-- 弹窗表单 -->
    <FormDialog v-model:formStatus="formStatus" v-model:form="form" @handleSuccess="handleSuccess" />
  </div>
</template>

<script setup lang="ts" name="expressInfo">
import SearchTable from "@/components/user/expressInfo/SearchTable.vue";
import FormDialog from "@/components/user/expressInfo/FormDialog.vue";
import type { ViewMode, ViewModeFilter } from "@/types/common";
import type { IExpress } from "@/types/express";

const formStatus = ref<ViewMode>("none");

/* 表格子组件的引用 */
const searchTableRef = useTemplateRef("searchTableRef");

/* 表单数据 */
const form = reactive<IExpress>({
  id: 0,
  ex_com: "",
  ex_logo: "",
  ex_mobile: "",
  ex_name: "",
  sort: 0,
  status: 0
});

/* 点击编辑按钮 */
function handleViewEdit(row: IExpress, code: ViewModeFilter) {
  formStatus.value = code;
  /* nextTick 解决重置该表单项 初始化的数据问题 */
  nextTick(() => {
    form.id = row.id;
    form.ex_com = row.ex_com;
    form.ex_logo = row.ex_logo;
    form.ex_mobile = row.ex_mobile;
    form.ex_name = row.ex_name;
    form.sort = row.sort;
    form.status = row.status;
  });
}

/* 成功保存或者编辑的回调 */
function handleSuccess() {
  searchTableRef.value?.getTableInfo();
}
</script>

<style lang="scss" scoped></style>
